<?php
/*
 * Post Page
 */
?>

<?php get_header(); 
$theme = rand(1, 5);
?>

<div id="post-main" class="post-main<?php echo $theme; ?> content">
<div class="container12">
   
	
	<!-- Begin Main Content -->
	<div class="column9 alpha post_page_content">

		<?php 
		if(have_posts()): while(have_posts()): the_post(); 
		
			$meta = get_post_custom( $post->ID );
			
			// check to see if a quiz has been submitted or not
			$score = sfc_check_quiz_post($post->ID);
			if($score != 0) {
				?>
				<div id="form_post_message">
					<div id="form_post_message_inner">
						You scored a <?php echo $score; ?> on the quiz!
					</div>
				</div> 
				<?php 
			}
			?>
			
			<!-- Start Post Content -->
			<article class="post_content <?php post_class(); ?>" id="post-<?php the_ID(); ?>">

            		<!-- Title -->
				<div class="row post_title">
					<h1>
					<?php 
						if(empty($meta['meta_team_name'][0]))
							the_title(); 
						else
							echo $meta['meta_team_name'][0];
					?>
					</h1>
				</div>
				
				<div class="row post_team_summary">
					<!-- Team Picture -->
					<div class="post_team_pic">
						<?php the_post_thumbnail('large'); ?>
					</div>
					
					<!-- Subject and Summary -->
					<div class="post_summary border-box">
						<p>Topic: <?php echo $meta['meta_topic'][0]; ?></p>
						<p><?php echo $meta['meta_summary'][0]; ?></p>
					</div>
				</div>
				
				<!-- Student video -->
				<div class="post_student_video row">
					<?php echo $meta['meta_video'][0]; ?>
				</div>
				
				<!-- Article -->
				<div class="post_article row">
					<p><?php the_content(); ?></p>
				</div>
				
				<!-- Expert video -->
				<div class="post_expert_video row">
					<?php echo $meta['meta_video'][0]; ?>
				</div>
				
				<!-- Blog Link -->
				<div class="post_blog row">
					<p>We are writing about our experiences, <a href="<?php echo $meta['meta_blog'][0]; ?>">visit our blog</a> for more information!</p>
				</div>
				
				<!-- Call to Action -->
				<div class="post_call_to_action row">
					<p><?php echo $meta['meta_call'][0]; ?></p>
				</div>
				
				
				
			</article>
			<!-- End Post Content -->
			
			<!-- Begin Quiz Section -->
			<div id="post_quiz">
				<?php 
				// user has not taken this quiz yet
				if(sfc_user_has_taken_quiz($post->ID) || $score != 0) {
					echo '<h2>You have already taken this quiz!</h2>';
				} else {
				?>
					<h2>Quiz!</h2>
					<form method="post">
						<div class="row">
							<div class="question column6">
								<p><?php echo $meta['meta_quiz1_question'][0]; ?></p>
								<?php 
									echo sfc_build_quiz_radio_buttons("quiz1", $meta['meta_quiz1_correct'][0], $meta['meta_quiz1_wrong1'][0], $meta['meta_quiz1_wrong2'][0], $meta['meta_quiz1_wrong3'][0]);
								?>
							</div>
							<div class="question column6">
								<p><?php echo $meta['meta_quiz2_question'][0]; ?></p>
								<?php 
									echo sfc_build_quiz_radio_buttons("quiz2", $meta['meta_quiz2_correct'][0], $meta['meta_quiz2_wrong1'][0], $meta['meta_quiz2_wrong2'][0], $meta['meta_quiz2_wrong3'][0]);
								?>
							</div>
							<div class="question column6">
								<p><?php echo $meta['meta_quiz3_question'][0]; ?></p>
								<?php 
									echo sfc_build_quiz_radio_buttons("quiz3", $meta['meta_quiz3_correct'][0], $meta['meta_quiz3_wrong1'][0], $meta['meta_quiz3_wrong2'][0], $meta['meta_quiz3_wrong3'][0]);
								?>
							</div>
							<div class="question column6">
								<p><?php echo $meta['meta_quiz4_question'][0]; ?></p>
								<?php 
									echo sfc_build_quiz_radio_buttons("quiz4", $meta['meta_quiz4_correct'][0], $meta['meta_quiz4_wrong1'][0], $meta['meta_quiz4_wrong2'][0], $meta['meta_quiz4_wrong3'][0]);
								?>
							</div>
							<div class="question column6">
								<p><?php echo $meta['meta_quiz5_question'][0]; ?></p>
								<?php 
									echo sfc_build_quiz_radio_buttons("quiz5", $meta['meta_quiz5_correct'][0], $meta['meta_quiz5_wrong1'][0], $meta['meta_quiz5_wrong2'][0], $meta['meta_quiz5_wrong3'][0]);
								?>
							</div>
						</div>
						<input type="submit" value="Submit!" class="submit_go">
					</form>
				<?php 
				}
				?>
				
				
			</div>
			<!-- End Quiz Section -->
						
		<?php 
		endwhile; endif; 
		?>
		
		<!-- Recent posts -->
		<div class="row">
			<div class="post_recent_posts border-box">
			
				<?php
					$args = array( 'numberposts' => '4' );
					$recent_posts = wp_get_recent_posts( $args );
					$c = 1;
					foreach($recent_posts as $recent) {
						if( ($c <= 3) && ($recent["ID"] != $post->ID) ) {
							$recent_meta = get_post_custom($recent["ID"]);
							echo '<div class="post_recent_post column4">';
							echo '		<div class="thumb">';
							echo '			<a href="' . get_permalink($recent["ID"]) . '">';
							echo 				get_the_post_thumbnail($recent['ID'], 'thumbnail');
							echo '			</a>';
							echo '		</div>';
							echo '		<a href="' . get_permalink($recent["ID"]) . '">';
										if(empty($recent_meta["meta_team_name"][0]))
											$recent["post_title"]; 
										else
											echo $recent_meta["meta_team_name"][0];
							echo '		</a>';
							echo '		<p>' . $recent_meta['meta_summary'][0] . '</p>';
							echo '</div>';
							$c++;
						}
					}
				?>
				
			</div>
		</div>
		
		<!-- edit post -->
		<div class="row">
			<?php edit_post_link(); ?>
		</div>
	
	</div>
	<!-- End Main Content -->
	
	
	<!-- Sidebar Content -->
	<div class="column3 omega post_page_sidebar">
		<?php get_sidebar(); ?>
	</div>
	<!-- End Sidebar Content -->
		
	
</div>
</div>

<?php get_footer(); ?>